// pages/home/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputShowed: false,
    inputVal: "",
    situationList: [{
        id: 0,
        url: "../../../images/banner.png",
        text: "黄瓜根结线虫"
      },
      {
        id: 1,
        url: "../../../images/banner.png",
        text: "黄瓜根结线虫"
      },
      {
        id: 2,
        url: "../../../images/banner.png",
        text: "黄瓜根结线虫"
      },
      {
        id: 3,
        url: "../../../images/banner.png",
        text: "黄瓜根结线虫"
      },
      {
        id: 4,
        url: "../../../images/banner.png",
        text: "黄瓜根结线虫"
      },
      {
        id: 5,
        url: "../../../images/banner.png",
        text: "黄瓜根结线虫"
      },
      {
        id: 6,
        url: "../../../images/banner.png",
        text: "黄瓜根结线虫"
      },
      {
        id: 7,
        url: "../../../images/banner.png",
        text: "黄瓜根结线虫"
      },
    ],
    images: []
  },

  albumChoose: function (e) {
    let that = this
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album'],
      success(res) {
        console.log(res,888)
        // tempFilePath可以作为img标签的src属性显示图片
        const images = that.data.images.concat(res.tempFilePaths)
        wx.navigateTo({
          url: `/pages/virus_recognition/image-cropper/index?src=${images}`,
          success: function (res) {
            wx.setNavigationBarTitle({
              title: '照片'
            })
            // 通过eventChannel向被打开页面传送数据
            // res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'test' })
          }
        })
      }
    })
  },

  photographChoose: function (e) {
    let that = this
    wx.chooseImage({
      count: 0,
      sizeType: ['original', 'compressed'],
      sourceType: ['camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const images = that.data.images.concat(res.tempFilePaths)
        wx.navigateTo({
          url: `/pages/virus_recognition/image-cropper/index?src=${images}`,
          success: function (res) {
            wx.setNavigationBarTitle({
              title: '照片'
            })
            // 通过eventChannel向被打开页面传送数据
            // res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'test' })
          }
        })
      }
    })
  },

  search: function (value) {
    console.log(value,8989)
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve([{
          text: '搜索结果',
          value: 1
        }, {
          text: '搜索结果2',
          value: 2
        }])
      }, 200)
    })
  },
  selectResult: function (e) {
    console.log('select result', e.detail)
  },

  goPages: function (e) {
    wx.navigateTo({
      url: `/pages/virus_recognition/virus-details/index`,
      success: function (res) {
        wx.setNavigationBarTitle({
          title: '病害详情'
        })
        // 通过eventChannel向被打开页面传送数据
        // res.eventChannel.emit('acceptDataFromOpenerPage', { data: 'test' })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      search: this.search.bind(this)
    })


    // if (typeof this.getTabBar === 'function' && this.getTabBar()) {
    //   console.log(12121)
    //   this.getTabBar().setData({
    //     selected: app.globalData.selected
    //   })
    // }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // if (typeof this.getTabBar === 'function' && this.getTabBar()) {
    //   console.log(12121)
    //   this.getTabBar().setData({
    //     selected: app.globalData.selected
    //   })
    // }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})